﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBEngine.Elements;

namespace FilingSystem
{
    public partial class FilingSystemForm : Form
    {
        public FilingSystemForm()
        {
            InitializeComponent();
        }

        private void FilingSystemForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the '_CVC_DatabaseDataSet_Form.ClientInfo' table. You can move, or remove it, as needed.
            this.clientInfoTableAdapter.Fill(this._CVC_DatabaseDataSet_Form.ClientInfo);

        }

        //private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        //{

        //}
        private void clientsInfoDataGridView_SelectionChanged(object sender, System.EventArgs e)
        {
            Int32 selectedRowCount =
                clientsInfoDataGridView.Rows.GetRowCount(DataGridViewElementStates.Selected);
            if (selectedRowCount > 0)
            {
                this.mSelectedClientRow = this.clientsInfoDataGridView.SelectedRows[0];
                this.mSelectedClientInfo = ParseClientInfo(this.mSelectedClientRow);
<<<<<<< .mine
                //updateClientInfoPanelTextBox();
=======
                updateClientInfoPanelTextBox();
>>>>>>> .r10
            }
        }
        //help methods

        ClientInfo ParseClientInfo(DataGridViewRow row)
        {
            ClientInfo retval = new ClientInfo();
            int i = 0;
            foreach (ClientInfo.Fields clientField in Enum.GetValues(typeof(ClientInfo.Fields)))
            {
                Object cellValue = row.Cells[i++].Value;
                if (Convert.IsDBNull(cellValue) == true)
                    cellValue = null;
                retval[clientField] = cellValue;
            }
            return retval;
        }

        void updateClientInfoPanelTextBox()
        {
            if (this.mSelectedClientInfo == null)
                return;

<<<<<<< .mine
            foreach (KeyValuePair<ClientInfo.Fields, System.Windows.Forms.TextBox> pair in mClientInfoPanelTextBoxs)
            {
                Object value = mSelectedClientInfo[pair.Key];
                value = value == null ? "" : value;
                pair.Value.Text = value.ToString();
            }
            if (mSelectedClientInfo[ClientInfo.Fields.DateOfBirth] != null)
            {
               // this.dateOfBirthTextBox.Text = ((DateTime)(mSelectedClientInfo[ClientInfo.Fields.DateOfBirth])).ToString("dd/MM/yyyy");
            }
=======
            
            foreach (KeyValuePair<ClientInfo.Fields, System.Windows.Forms.TextBox> pair in mClientInfoPanelTextBoxs)
            {
                Object value = mSelectedClientInfo[pair.Key];
                value = value == null ? "" : value;
                pair.Value.Text = value.ToString() ;
            }
            if (mSelectedClientInfo[ClientInfo.Fields.DateOfBirth] != null)
            {
                this.dateOfBirthTextBox.Text = ((DateTime)(mSelectedClientInfo[ClientInfo.Fields.DateOfBirth])).ToString("dd/MM/yyyy");
            }
>>>>>>> .r10
        }
    }
}
